package com.cskaoyan.controller;

import com.cskaoyan.bean.vo.back.BaseRespVo;

import com.cskaoyan.bean.vo.statvo.GoodsColumns;
import com.cskaoyan.bean.vo.statvo.OrderColumns;
import com.cskaoyan.bean.vo.statvo.StatUserVo;

import com.cskaoyan.bean.vo.statvo.UserColumns;
import com.cskaoyan.service.AdminStatService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: SSMItem
 * @description 该controller实现统计报表
 * @author: YY
 * @create: 2022-10-12 13:08
 **/
@RestController
@RequestMapping("admin/stat")
public class AdminStatController {
    @Autowired
    AdminStatService adminStatService;


    /**
     * 用户统计
     * 请求url：http://localhost：8083/admin/stat/user
     *
     * @return
     */
    @RequiresPermissions("admin:stat:user")
    @GetMapping("user")
    public BaseRespVo statUser() {

        List<UserColumns> columnsList = adminStatService.selectUser();
        StatUserVo user = new StatUserVo();
        String[] columns = {"day", "users"};
        user.setColumns(columns);
        user.setRows(columnsList);
        return BaseRespVo.ok(user);

    }

    /**
     * 订单统计
     * 请求url：http://localhost：8083/admin/stat/order
     *
     * @return
     */
    @RequiresPermissions("admin:stat:order")
    @GetMapping("order")
    public BaseRespVo statOrder() {

        String[] columns = {"day", "orders", "customers", "amount", "pcr"};
        StatUserVo<OrderColumns> columnsStatUserVo = new StatUserVo<>();

        List<OrderColumns> orderList = adminStatService.selectOrder();
        columnsStatUserVo.setColumns(columns);
        columnsStatUserVo.setRows(orderList);
        return BaseRespVo.ok(columnsStatUserVo);

    }

    /**
     * 商品统计
     * 请求url：http://localhost：8083/admin/stat/goods
     *
     * @return
     */
    @RequiresPermissions("admin:stat:goods")
    @GetMapping("goods")
    public BaseRespVo statGoods() {

        String[] columns = {"day", "orders", "products", "amount"};
        StatUserVo<GoodsColumns> columnsStatUserVo = new StatUserVo<>();

        List<GoodsColumns> goodsColumnsList = adminStatService.selectGoods();

        columnsStatUserVo.setColumns(columns);
        columnsStatUserVo.setRows(goodsColumnsList);

        return BaseRespVo.ok(columnsStatUserVo);

    }


}
